@extends('layouts.app')

<style type="text/css">
    body, html{width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}
    #allmap{height:100%;width:100%;}
    #r-result{width:100%; font-size:14px;}
</style>

@section('content')
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=hrVnXxLAGVr6QZ0rt9MaxU8bBkwKzyQC"></script>
    <div class="content">
        <div style="border-left: 1px solid #cccccc;">
            {{--<span id="lastinfo" style="display: none">{{$lasjson}}</span>--}}
            <div id="allmap"></div>
        </div>
    </div>
    <script type="text/javascript">
        function changesearch() {
            var keywords = $('#keywords').val();

            if (!keywords) {
                alert('名称不能为空');
                return false;
            }

            $('#search_form').submit();
        }

        // 百度地图API功能
        map = new BMap.Map("allmap");
        map.centerAndZoom(new BMap.Point(114.349665, 30.581697), 18);

        $.get("get_units",function(data,status){
            //alert(data);die;
            var data_info = data;
            //alert(data_info);die;
            var opts = {
                width: 300, // 信息窗口宽度
                height: 0, // 信息窗口高度
                title: "", // 信息窗口标题
                enableMessage: true//设置允许信息窗发送短息
            };
            for (var i = 0; i < data_info.length; i++) {
                var marker = new BMap.Marker(new BMap.Point(data_info[i][0], data_info[i][1]));  // 创建标注
                var content = data_info[i][2];
                map.addOverlay(marker);               // 将标注添加到地图中
                addClickHandler(content, marker);
            }
            function addClickHandler(content, marker) {
                marker.addEventListener("click", function (e) {
                            openInfo(content, e)
                        }
                );
            }
            function openInfo(content, e) {
                var p = e.target;
                var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
                var infoWindow = new BMap.InfoWindow(content, opts);  // 创建信息窗口对象
                map.openInfoWindow(infoWindow, point); //开启信息窗口
            }
        });


    </script>
@stop

